<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        const arr = [{
                name: "a",
                id: 1
            },
            {
                name: "b",
                id: 2
            },
            {
                name: "c",
                id: 3
            },
            {
                name: "d",
                id: 4
            },
            {
                name: "e",
                id: 5
            },
            {
                name: "f",
                id: 6
            },
            {
                name: "g",
                id: 7
            }
        ]

        //找到id为5的对象
        const result = arr.find(item => item.id === 5)
        const resultIndex = arr.findIndex(item => item.id === 5)

        console.log(result, resultIndex);
    </script>
</body>

</html>